package leetcode;

import pojo.TreeNode;

/**
 * 101. 对称二叉树   https://leetcode.cn/problems/symmetric-tree/description/
 *
 * @author yujiafan
 * @version 1.0.0
 * @create 2022-12-27
 */
public class LeetCode101 {

    public boolean isSymmetricTree(TreeNode r1, TreeNode r2) {
        if (r1 == null ^ r2 == null) {
            return false;
        }
        if (r1 == null && r2 == null) {
            return true;
        }
        return r1.val == r2.val && isSymmetricTree(r1.left, r2.right) && isSymmetricTree(r1.right, r2.left);
    }

    public boolean isSymmetric(TreeNode root) {
        return isSymmetricTree(root, root);
    }
}
